package oh.june.keepscreenonwatch;

import java.util.ArrayList;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.TextView;

public class AppListAdapter extends ArrayAdapter<ApplicationInfo>{
	
	private static int LAYOUT = R.layout.list_applist2;
	private LayoutInflater mInflater;
	private Context _context;
	private PackageManager _pm;
	
	private ArrayList<ApplicationInfo> _checkedInfoList = new ArrayList<ApplicationInfo>();
	
	public AppListAdapter(Context context, PackageManager pm) {
		super(context, LAYOUT);
		_context = context;
		_pm = pm;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public View getView(final int position, final View convertView, ViewGroup parent) {
		View v = convertView;
		if(v == null){
			v = mInflater.inflate(LAYOUT, null);
		}
		
		final ApplicationInfo info = getItem(position);
		
		ImageView imv = (ImageView)v.findViewById(R.id.img_view);
		TextView txt = (TextView)v.findViewById(R.id.txt_view);
		
		imv.setImageDrawable(info.loadIcon(_pm));
		txt.setText(_pm.getApplicationLabel(info));
		return v;
	}
	
	
	public ArrayList<ApplicationInfo> getCheckedInfoList(){
		return _checkedInfoList;
	}
	
	
}
